/*
 * UserXML.java
 *
 * Created on 28 sierpień 2007, 16:49
 *
 */

package pl.krakow.knp.wikiboard.server.xml;

import nu.xom.Attribute;
import nu.xom.Element;

/**
 *
 * @author Michał
 */
public class UserXML {
    
    private int id;
    private String name;
    private boolean leader;
    
    /** Creates a new instance of UserXML */
    public UserXML(int id, String name, boolean leader) {
        this.id = id;
        this.name = name;
        this.leader = leader;
    }
    
    public UserXML(Element user) {
        id = Integer.parseInt(user.getAttributeValue("id"));
        name = user.getAttributeValue("name");
        leader = (user.getAttributeValue("leader")).equals("true") ? true : false;
    }
    
    public Element getXML() {
        Element user = new Element("user");
        Attribute aId = new Attribute("id",String.valueOf(getId()));
        Attribute aName = new Attribute("name", getName());
        Attribute aLeader = new Attribute("leader",String.valueOf(isLeader()));
        user.addAttribute(aId);
        user.addAttribute(aName);
        user.addAttribute(aLeader);
        return user;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public boolean isLeader() {
        return leader;
    }
}
